Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove global structure in LCD HAL Layer #6597

Merged
merged 1 commit into from
Jan 3, 2025

Conversation

abhinav-s235
Copy link
Contributor

@abhinav-s235 abhinav-s235 commented Dec 24, 2024

Replaced the global LCD HAL layer instance with a local declaration within the lcddev_register() function to reduce memory usage and passed this instance to LCD_FLUSH_THREAD by converting its address to a string using atoi() function.

@abhinav-s235 abhinav-s235 changed the title os/drivers/lcd/lcd_dev.c: Declare LCD HAL layer instance locally inside lcddev_register() function Remove global structure in LCD HAL Layer Dec 24, 2024

int pid = kernel_thread("LCD Frame flusing", 204, 8192, lcd_flushing_thread, NULL);
itoa((int)lcd_info, parm_buf, 16);
parm[0] = parm_buf;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param[0] = itoa((int)lcd_info, parm_buf, 16);

And don't we need to memset parm_buf?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why we need to convert it to ascii and to reconvert to integer.
Is it possible to give the address itself without converting?

Copy link
Contributor Author

@abhinav-s235 abhinav-s235 Dec 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not possible to pass the address without converting it to string because kernel_thread() function accept the parameter of type FAR char *const argv[].
int kernel_thread(FAR const char *name, int priority, int stack_size, main_t entry, FAR char *const argv[])

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

param[0] = itoa((int)lcd_info, parm_buf, 16);

And don't we need to memset parm_buf?

I don't think it is needed
could you please explain why you think so?

Copy link
Contributor

@sunghan-chang sunghan-chang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you leave why you modify this in the COMMIT description? I can't get why you did.

Comment on lines 427 to 428
char *parm[2];
char parm_buf[9]; /* for storing 32 bit address */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The param and param_buf are difficult to distinguish and to know what they are. Could you rename them to know what they are in name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The param and param_buf are difficult to distinguish and to know what they are. Could you rename them to know what they are in name?

fixed


int pid = kernel_thread("LCD Frame flusing", 204, 8192, lcd_flushing_thread, NULL);
itoa((int)lcd_info, parm_buf, 16);
parm[0] = parm_buf;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why we need to convert it to ascii and to reconvert to integer.
Is it possible to give the address itself without converting?

@sunghan-chang
Copy link
Contributor

Could you leave why you modify this in the COMMIT description? I can't get why you did.

@abhinav-s235 Could you check my comment above? I mean why you did below

Replaced the global LCD HAL layer instance with a local declaration within the lcddev_register function
and passed this instance to LCD_FLUSH_THREAD by converting its address to a string using atoi() function.

@abhinav-s235
Copy link
Contributor Author

Could you leave why you modify this in the COMMIT description? I can't get why you did.

Previously, while creating frame flushing thread we were not passing lcd_info pointer to function lcd_flushing_thread() that's why we declared it globally but now we are passing it as a parameter to the lcd_flushing_thread() function there is no need to globally declare it.

os/drivers/lcd/lcd_dev.c Outdated Show resolved Hide resolved
@@ -423,13 +424,15 @@ int lcddev_register(struct lcd_dev_s *dev)
{
char devname[16] = { 0, };
int ret;
char *task_info[2];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about flushing_thread_args?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@abhinav-s235 Could you check my comment above?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about flushing_thread_args?

It has been changed

@sunghan-chang
Copy link
Contributor

Could you leave why you modify this in the COMMIT description? I can't get why you did.

Previously, while creating frame flushing thread we were not passing lcd_info pointer to function lcd_flushing_thread() that's why we declared it globally but now we are passing it as a parameter to the lcd_flushing_thread() function there is no need to globally declare it.

The point is you want to remove the global variable. Right? Is that to reduce memory usages?
And Let's leave it at the COMMIT description.

@abhinav-s235
Copy link
Contributor Author

Could you leave why you modify this in the COMMIT description? I can't get why you did.

Previously, while creating frame flushing thread we were not passing lcd_info pointer to function lcd_flushing_thread() that's why we declared it globally but now we are passing it as a parameter to the lcd_flushing_thread() function there is no need to globally declare it.

The point is you want to remove the global variable. Right? Is that to reduce memory usages? And Let's leave it at the COMMIT description.

Commit description has been changed.

}
cleanup:
lcddbg("ERROR: Failed to register driver %s\n", devname);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indentation should be tab

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@sunghan-chang
Copy link
Contributor

@abhinav-s235 Is this verified with real device?

sunghan-chang
sunghan-chang previously approved these changes Jan 2, 2025
@abhinav-s235
Copy link
Contributor Author

@abhinav-s235 Is this verified with real device?

Yes


if (!dev) {
return -EINVAL;
}

/* Allocate a new lcd_dev driver instance */
lcd_info = (struct lcd_s *)kmm_zalloc(sizeof(struct lcd_s));
struct lcd_s *lcd_info = (struct lcd_s *)kmm_zalloc(sizeof(struct lcd_s));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's move Variable declaration on top

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

itoa((int)lcd_info, lcd_info_addr, 16);
flushing_thread_args[0] = lcd_info_addr;
flushing_thread_args[1] = NULL;
int pid = kernel_thread("LCD Frame flusing", 204, 8192, lcd_flushing_thread, (FAR char *const *)flushing_thread_args);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It also, Let's move variable declaration on top

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

#endif
struct lcd_s *lcd_info;
char *flushing_thread_args[2];
char lcd_info_addr[9]; /* for storing 32 bit address */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be in the CONFIG_LCD_FLUSH_THREAD conditional.
If not, when we disable the config, it will be unused variable warning.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

@@ -441,12 +448,19 @@ int lcddev_register(struct lcd_dev_s *dev)
lcd_info->empty = true;
lcd_info->lcd_kbuffer = (uint8_t *)kmm_malloc(CONFIG_LCD_XRES * CONFIG_LCD_YRES * sizeof(uint16_t));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The members - do_wait, empty and lcd_kbuffer are valid with the config - CONFIG_LCD_FLUSH_THREAD only?
When the config is disable, they are not used?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, these members are only valid when config CONFIG_LCD_FLUSH_THREAD is enabled
struct lcd_s

…de lcddev_register function

Replaced the global LCD HAL layer instance with a local declaration within the lcddev_register function to
reduce memory usage and passed this instance to LCD_FLUSH_THREAD by converting its address to a string using atoi() function.
@sunghan-chang sunghan-chang merged commit f36c01e into Samsung:master Jan 3, 2025
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants